<template>
  <div class="js-page">
    <h1>JavaScript 面试题介绍</h1>
    <div class="js-container">
      <!-- 左侧导航栏 -->
      <nav class="js-sidebar">
        <ul>
          <li v-for="(item, index) in categories" :key="index" :class="{ active: activeIndex === index }" @click="setActive(index)">
            {{ item.name }}
          </li>
        </ul>
      </nav>
      <!-- 右侧内容展示 -->
      <div class="js-content">
        <router-view></router-view> <!-- 子页面内容动态渲染 -->
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const categories = [
  { name: '介绍', path: 'intro' },
  { name: '类型转换', path: 'type-conversion' },
  { name: 'null 和 undefined', path: 'null-undefined' },
  { name: '类型判断', path: 'type-check' },
  { name: '相等判断', path: 'equals' }
]

const activeIndex = ref(0)
</script>

<style scoped lang="scss">
.js-page {
  padding: 20px;

  h1 {
    text-align: center;
    margin-bottom: 20px;
    font-size: 2.5em;
    color: #333;
  }
}

.js-container {
  display: flex;
  gap: 20px;

  .js-sidebar {
    width: 250px;
    background-color: #f5f5f5;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

    ul {
      list-style: none;
      padding: 0;

      li {
        padding: 10px;
        cursor: pointer;
        border-bottom: 1px solid #ddd;
        transition: background 0.3s;
      }

      li:hover {
        background: #e0e0e0;
      }

      li.active {
        background: linear-gradient(45deg, #ff7e5f, #feb47b);
        color: white;
        font-weight: bold;
      }
    }
  }

  .js-content {
    flex: 1;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
}
</style>
